package forum_system_test;

import org.junit.jupiter.api.*;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

/**
 * @author tongchen
 * @create 2023-08-18 17:53
 */
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
public class HomePageTest {
    private static ChromeDriver chromeDriver= TestUtils.getDriver();
    @BeforeAll
    public static void getUrlAndLogin() throws InterruptedException {
        chromeDriver.get("http://47.93.222.41:58080/sign-in.html");
        WebElement element = chromeDriver.findElement(By.cssSelector("#username"));
        WebElement element1 = chromeDriver.findElement(By.cssSelector("#password"));
        WebElement element2 = chromeDriver.findElement(By.cssSelector("#submit"));
        element.clear();
        element1.clear();
        element.sendKeys("刘健磊");
        element1.sendKeys("123456");
        //强制等待一秒，使新页面能加载出来
        element2.click();
        Thread.sleep(5000);
    }
    @Order(1)
    @Test
    public void testNavicat() throws InterruptedException {
        //点击导航栏的各个属性判断属性是否正常
        //查看当前句柄
        String windowHandle = chromeDriver.getWindowHandle();
        //切换句柄
        chromeDriver.switchTo().window(windowHandle);
        //查找各个导航栏中的元素并进行点击
        chromeDriver.findElement(By.cssSelector("#topBoardList > li:nth-child(2) > a > span.nav-link-title")).click();
        Thread.sleep(1000);
        chromeDriver.findElement(By.cssSelector("#topBoardList > li:nth-child(3) > a > span.nav-link-title")).click();
        Thread.sleep(1000);
        chromeDriver.findElement(By.cssSelector("#topBoardList > li:nth-child(4) > a > span.nav-link-title")).click();
        Thread.sleep(1000);
        chromeDriver.findElement(By.cssSelector("#topBoardList > li:nth-child(5) > a > span.nav-link-title")).click();
        Thread.sleep(1000);
        chromeDriver.findElement(By.cssSelector("#topBoardList > li:nth-child(6) > a > span.nav-link-title")).click();
        Thread.sleep(1000);
        chromeDriver.findElement(By.cssSelector("#topBoardList > li:nth-child(7) > a > span.nav-link-title")).click();
        Thread.sleep(1000);
        chromeDriver.findElement(By.cssSelector("#topBoardList > li:nth-child(8) > a > span.nav-link-title")).click();
        Thread.sleep(1000);
        chromeDriver.findElement(By.cssSelector("#topBoardList > li:nth-child(9) > a > span.nav-link-title")).click();
        Thread.sleep(1000);
        chromeDriver.findElement(By.cssSelector("#topBoardList > li:nth-child(10) > a > span.nav-link-title")).click();
        Thread.sleep(1000);
        chromeDriver.findElement(By.cssSelector("body > div.page > header.navbar.navbar-expand-md.navbar-light.d-print-none > div > div > div:nth-child(2) > a.nav-link.px-0.hide-theme-dark > svg > path:nth-child(2)")).click();
        Thread.sleep(1000);
        chromeDriver.findElement(By.cssSelector("body > div.page > header.navbar.navbar-expand-md.navbar-light.d-print-none > div > div > div:nth-child(2) > div > a > svg")).click();
        Thread.sleep(1000);
       // chromeDriver.findElement(By.cssSelector("#index_nav_avatar")).click();
        //切换句柄至当前指向的窗口
        String windowHandle1 = chromeDriver.getWindowHandle();
        chromeDriver.switchTo().window(windowHandle1);
        //点击
        chromeDriver.findElement(By.cssSelector("#index_div_message_list > div:nth-child(1) > div > div.col.text-truncate > a > span:nth-child(2)")).click();

    }
    @Order(2)
    @Test
    public  void testMain(){
        //查看当前句柄
        String windowHandle = chromeDriver.getWindowHandle();
        //切换句柄
        chromeDriver.switchTo().window(windowHandle);
        //查找主页面中的元素进行点击
        chromeDriver.findElement(By.cssSelector("#artical-items-body > div:nth-child(1) > div > div.col > div.text-truncate > a > strong")).click();
    }
    @Order(3)
    @Test
    public  void testMain1(){
        chromeDriver.findElement(By.cssSelector("#bit-forum-content > div.page-header.d-print-none > div > div > div.col-auto.ms-auto.d-print-none > div > a.btn.btn-primary.d-none.d-sm-inline-block.article_post")).click();
    }
}

